package com.youbang.base.controller;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.youbang.common.ErrorCode;
import com.youbang.common.JSONResultModel;

@RestController
public class BaseController {

    public Object JsonResult(ErrorCode code, Object value) {
        JSONResultModel model = new JSONResultModel();
        model.setCode(code.ordinal());
        model.setValue(value);
        return JSONObject.toJSON(model);
    }

    public Object JsonResult(ErrorCode errCode, String errMsg){
        JSONResultModel model = new JSONResultModel();
        model.setCode(errCode.getCode());
        model.setMessage(errMsg);
        return JSONObject.toJSON(model);
    }

    public Object JsonResult(ErrorCode errCode){
        JSONResultModel model = new JSONResultModel();
        model.setCode(errCode.getCode());
        model.setMessage(errCode.getMsg());
        return JSONObject.toJSON(model);
    }
}
